package com.sunwayworld.basemodule.coredata.test.service.impl;

import com.sunwayworld.basemodule.coredata.test.bean.LimsTestMethodMaterialBean;
import com.sunwayworld.basemodule.coredata.test.dao.LimsTestMethodMaterialDao;
import com.sunwayworld.basemodule.coredata.test.service.LimsTestMethodMaterialService;
import com.sunwayworld.framework.at.annotation.AuditTrailEntry;
import com.sunwayworld.framework.at.annotation.AuditTrailType;
import com.sunwayworld.framework.context.ApplicationContextHelper;
import com.sunwayworld.framework.restful.data.RestJsonWrapperBean;
import com.sunwayworld.framework.spring.annotation.GikamBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Repository
@GikamBean
public class LimsTestMethodMaterialServiceImpl implements LimsTestMethodMaterialService {

    @Autowired
    private LimsTestMethodMaterialDao limsTestMethodMaterialDao;

    @Override
    @SuppressWarnings("unchecked")
    public LimsTestMethodMaterialDao getDao() {
        return limsTestMethodMaterialDao;
    }

    @Override
    @Transactional
    @AuditTrailEntry(AuditTrailType.INSERT)
    public Long insert(RestJsonWrapperBean jsonWrapper) {
        List<LimsTestMethodMaterialBean> limsTestMethodMaterials = jsonWrapper.parse(LimsTestMethodMaterialBean.class);
        limsTestMethodMaterials.forEach(t -> t.setId(ApplicationContextHelper.getNextIdentity()));
        getDao().insert(limsTestMethodMaterials);
        return limsTestMethodMaterials.get(0).getId();
    }

}
